package main

import (
	"fmt"
	"runtime"
)

/**
return : 返回当前函数调用，return之前的的defer生效
Goexit :  退出当前go程，如果调用test这个方法之前有被go修饰那么不会结束整个go程，如果没有这个将会结束整个go程
			Goexit之前注册的defer都生效
*/
/**
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
11111111111111111111111
B.defer
A.defer
*/
func test() {
	fmt.Println("11111111111111111111111")
	//return
	runtime.Goexit()
	//这段内容不会生效，因为注册还没来得及就返回了，如果是在return之前就可以
	defer fmt.Println("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
}

func main() {
	go func() {
		defer fmt.Println("A.defer")
		func() {
			fmt.Println("qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq")
			defer fmt.Println("B.defer")
			test()
			fmt.Println("2222222222222222222222222222222222222222222")
		}()

		fmt.Println("A") // 不会执行
	}() //不要忘记()

	//死循环，目的不让主goroutine结束
	for {

	}
}
